<template>
    <div class="app-container">
        <a-card>
            <BasicTable ref="tableRef" :params="params" :columns="columns" :query="query" @select-change="selectChange">
                <template #form>
                    <a-form-item label="职务编码" name="code">
                        <a-input v-model:value="params.code" placeholder="请输入职务编码" />
                    </a-form-item>
                    <a-form-item label="职务名称" name="name">
                        <a-input v-model:value="params.name" placeholder="请输入职务名称" />
                    </a-form-item>
                </template>
                <template #button>
                    <a-button v-permission="'system:job:delete'" type="primary" danger :disabled="isDisable" @click="batchDel(batchDelete, tableRef)">
                        <template #icon>
                            <DeleteOutlined />
                        </template>
                        删除
                    </a-button>
                    <a-button v-permission="'system:job:add'" type="primary" @click="open(modalRef)">
                        <template #icon>
                            <PlusOutlined />
                        </template>
                        新增
                    </a-button>
                </template>
                <template #table="{ body }">
                    <template v-if="body.column.key === 'status'">
                        <Switch v-model:checked="body.record.status" @change="switchChange(updateStatus, body.record.id, $event)" />
                    </template>
                    <template v-if="body.column.key === 'createDate'">
                        {{ parseTime(body.record.createDate) }}
                    </template>
                    <template v-if="body.column.key === 'action'">
                        <a-button v-permission="'system:job:edit'" type="link" @click="open(modalRef, body.record)">
                            <template #icon>
                                <EditOutlined />
                            </template>
                            编辑
                        </a-button>
                        <a-popconfirm title="确定要删除吗?" @confirm="del(deleteById, body.record.id, tableRef)">
                            <a-button v-permission="'system:job:delete'" type="link">
                                <template #icon>
                                    <DeleteOutlined />
                                </template>
                                删除
                            </a-button>
                        </a-popconfirm>
                    </template>
                </template>
            </BasicTable>
        </a-card>
        <Modal ref="modalRef" @close="refresh(tableRef)" />
    </div>
</template>
<script setup name="JobModule">
import { reactive, ref } from 'vue'
import { PlusOutlined, DeleteOutlined, EditOutlined } from '@ant-design/icons-vue'
import { query, deleteById, batchDelete, updateStatus } from '/@/api/System/Job'
import { useBasicTable } from '@iframe/tools/mixins/BasicTableMixins'
import { BasicTable, Switch } from '@iframe/tools/components'
import Modal from './Modal.vue'

const { refresh, isDisable, batchDel, selectChange, switchChange, del, open } = useBasicTable()

const tableRef = ref()
const modalRef = ref()

const params = reactive({
    code: null,
    name: null
})
const columns = [
    {
        title: '职务编码',
        dataIndex: 'code',
        key: 'code',
        width: 300
    },
    {
        title: '职务名称',
        dataIndex: 'name',
        key: 'name'
    },
    {
        title: '状态',
        dataIndex: 'status',
        key: 'status',
        align: 'center',
        width: 200
    },
    {
        title: '创建时间',
        dataIndex: 'createDate',
        key: 'createDate',
        align: 'center',
        width: 200
    },
    {
        title: '操作',
        key: 'action',
        align: 'center',
        width: 260
    }
]
</script>
